#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>

using  namespace std;



bool cmp(const int & a, const int & b)
{
    return  a > b;
}

int BeautifulDegree(string name)
{
    int count[26]={0};
//    transform(name.begin(), name.end(), name.begin(), ::tolower);

    for(int i = 0, size = name.size(); i != size; ++i)
    {
        cout<<name.at(i)<<endl;
        int temp = name.at(i) - 97;
        count[temp]++;
    }
    int sum = 0;
    sort(begin(count), end(count), cmp);
    for(int * beg = begin(count), * ed = end(count), value = 26;
        beg != ed;
        ++beg)
    {
        if(0 == *beg)
        {
            continue;
        }
        sum += (*beg) * value;
        value--;
    }
    return sum;
}
int main() {
//    vector<PCB> v;
//    input(v);
    cout<<BeautifulDegree("zhangsan")<<endl;
    return 0;
}

